home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / contrib / pdcurs22 / src / portable / scanw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-26  |  6.5 KB  |  229 lines

  1. /*
  2. ***************************************************************************
  3. * This file comprises part of PDCurses. PDCurses is Public Domain software.
  4. * You may use this code for whatever purposes you desire. This software
  5. * is provided AS IS with NO WARRANTY whatsoever.
  6. * Should this software be used in another application, an acknowledgement
  7. * that PDCurses code is used would be appreciated, but is not mandatory.
  8. *
  9. * Any changes which you make to this software which may improve or enhance
  10. * it, should be forwarded to the current maintainer for the benefit of 
  11. * other users.
  12. *
  13. * The only restriction placed on this code is that no distribution of
  14. * modified PDCurses code be made under the PDCurses name, by anyone
  15. * other than the current maintainer.
  16. * See the file maintain.er for details of the current maintainer.
  17. ***************************************************************************
  18. */
  19. #include <stdarg.h>
  20. #include <string.h>
  21. #define    CURSES_LIBRARY    1
  22. #include <curses.h>
  23.  
  24. /* undefine any macros for functions defined in this module */
  25. #undef    scanw
  26. #undef    wscanw
  27. #undef    mvscanw
  28. #undef    mvwscanw
  29. #undef    vwscanw
  30.  
  31. /* undefine any macros for functions called by this module if in debug mode */
  32. #ifdef PDCDEBUG
  33. #  undef    wgetstr
  34. #  undef    wrefresh
  35. #  undef    wmove
  36. #endif
  37.  
  38. #ifdef PDCDEBUG
  39. char *rcsid_scanw  = "$Id$";
  40. #endif
  41.  
  42. /*man-start*********************************************************************
  43.  
  44.   Name:                                                         scanw
  45.  
  46.   Synopsis:
  47.       int scanw(char *fmt, ...);
  48.       int wscanw(WINDOW *win, char *fmt, ...);
  49.       int mvscanw(int y, int x, char *fmt, ...);
  50.       int mvwscanw(WINDOW *win, int y, int x, char *fmt,...);
  51.   ***    int vwscanw(WINDOW *win, char *fmt, va_list varglist);
  52.  
  53.   X/Open Description:
  54.      These routines correspond to scanf(). The function scanw() reads
  55.      input from the default window. The function wscanw() reads
  56.      input from the specified window. The function mvscanw() moves
  57.      the cursor to the specified position and then reads input from
  58.      the default window. The function mvwscanw() moves the cursor to
  59.      the specified position and then reads input from the specified
  60.      window.
  61.  
  62.      For all the functions, the routine wgetstr() is called to get a
  63.      string from the window, and the resulting line is used as
  64.      input for the scan.  All character interpretation is carried
  65.      out according to the scanf function rules.
  66.  
  67.   PDCurses Description:
  68.      The old Bjorn Larssen code for the 68K platform has been removed
  69.      from this module.
  70.  
  71.   X/Open Return Value:
  72.      Upon successful completion, the scanw, mvscanw, mvwscanw and
  73.      wscanw functions return the number of items successfully
  74.      matched.  On end-of-file, they return EOF.  Otherwise they
  75.      return ERR.
  76.  
  77.   X/Open Errors:
  78.      No errors are defined for this function.
  79.  
  80.   Portability                             X/Open    BSD    SYS V
  81.                                           Dec '88
  82.       scanw                                 Y        Y       Y
  83.       wscanw                                Y        Y       Y
  84.       mvscanw                               Y        Y       Y
  85.       mvwscanw                              Y        Y       Y
  86.       vwscanw                               -        -      4.0
  87.  
  88. **man-end**********************************************************************/
  89.  
  90. /***********************************************************************/
  91. int    scanw(char *fmt, ...)
  92. /***********************************************************************/
  93. {
  94.     va_list args;
  95.     int    retval = ERR;
  96.  
  97. #ifdef PDCDEBUG
  98.     if (trace_on) PDC_debug("scanw() - called\n");
  99. #endif
  100.  
  101. #if    !defined (HC)
  102.     if (stdscr == (WINDOW *)NULL)
  103.         return( retval );
  104.  
  105.     wrefresh(stdscr);    /* set cursor position */
  106.  
  107.     /*
  108.      * get string
  109.      */
  110.     c_printscanbuf[0] = '\0';  /* reset to empty string */
  111.     if (wgetstr(stdscr, c_printscanbuf) == ERR)
  112.         return( retval );
  113.     va_start(args, fmt);
  114. #ifdef NO_VSSCANF
  115.     retval = PDC_vsscanf(c_printscanbuf, fmt, args);
  116. #else
  117.     retval = vsscanf(c_printscanbuf, fmt, args);
  118. #endif
  119.     va_end(args);
  120. #endif
  121.     return( retval );
  122. }
  123. /***********************************************************************/
  124. int    wscanw(WINDOW *win, char *fmt, ...)
  125. /***********************************************************************/
  126. {
  127.     va_list args;
  128.     int    retval = ERR;
  129.  
  130. #ifdef PDCDEBUG
  131.     if (trace_on) PDC_debug("wscanw() - called\n");
  132. #endif
  133.  
  134. #if    !defined (HC)
  135.     if (win == (WINDOW *)NULL)
  136.         return (retval);
  137.  
  138.     wrefresh(win);        /* set cursor position */
  139.  
  140.     /*
  141.      * get string
  142.      */
  143.     c_printscanbuf[0] = '\0';  /* reset to empty string */
  144.     if (wgetstr(win, c_printscanbuf) == ERR)
  145.         return( retval );
  146.     va_start(args, fmt);
  147. #ifdef NO_VSSCANF
  148.     retval = PDC_vsscanf(c_printscanbuf, fmt, args);
  149. #else
  150.     retval = vsscanf(c_printscanbuf, fmt, args);
  151. #endif
  152.     va_end(args);
  153. #endif
  154.     return( retval );
  155. }
  156. /***********************************************************************/
  157. int    mvscanw(int y, int x, char *fmt, ... )
  158. /***********************************************************************/
  159. {
  160.     va_list args;
  161.     int    retval = ERR;
  162.  
  163. #ifdef PDCDEBUG
  164.     if (trace_on) PDC_debug("mvscanw() - called\n");
  165. #endif
  166.  
  167. #if    !defined (HC)
  168.     if (stdscr == (WINDOW *)NULL)
  169.         return( retval );
  170.  
  171.     if (wmove(stdscr, y, x) == ERR)
  172.         return( retval );
  173.  
  174.     wrefresh(stdscr);            /* set cursor position */
  175.  
  176.     /*
  177.      * get string
  178.      */
  179.     c_printscanbuf[0] = '\0';  /* reset to empty string */
  180.     if (wgetstr(stdscr, c_printscanbuf) == ERR)
  181.         return( retval );
  182.     va_start(args, fmt);
  183. #ifdef NO_VSSCANF
  184.     retval = PDC_vsscanf(c_printscanbuf, fmt, args);
  185. #else
  186.     retval = vsscanf(c_printscanbuf, fmt, args);
  187. #endif
  188.     va_end(args);
  189. #endif
  190.     return( retval );
  191. }
  192. /***********************************************************************/
  193. int    mvwscanw(WINDOW *win, int y, int x, char *fmt,...)
  194. /***********************************************************************/
  195. {
  196.     va_list args;
  197.     int    retval = ERR;
  198.  
  199. #ifdef PDCDEBUG
  200.     if (trace_on) PDC_debug("mvscanw() - called\n");
  201. #endif
  202.  
  203. #if    !defined (HC)
  204.     if (win == (WINDOW *)NULL)
  205.         return( retval );
  206.  
  207.     if (wmove(win, y, x) == ERR)
  208.         return( retval );
  209.  
  210.     wrefresh(win);        /* set cursor position */
  211.  
  212.     /*
  213.      * get string
  214.      */
  215.     c_printscanbuf[0] = '\0';  /* reset to empty string */
  216.     if (wgetstr(win, c_printscanbuf) == ERR)
  217.         return( retval );
  218.     va_start(args, fmt);
  219. #ifdef NO_VSSCANF
  220.     retval = PDC_vsscanf(c_printscanbuf, fmt, args);
  221. #else
  222.     retval = vsscanf(c_printscanbuf, fmt, args);
  223. #endif
  224.     va_end(args);
  225. #endif
  226.     return( retval );
  227. }
  228.